package com.yimi.yinhepda.service;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.pda.ym.callbacks.UICallBack;
import com.yimi.yinhepda.db.dao.OffLineUnbindTableDao;
import com.yimi.yinhepda.db.table.OffLineUnbindTable;
import com.yimi.yinhepda.entity.request.OffLineUnBindRequest;
import com.yimi.yinhepda.entity.response.SuccessResponse;
import com.pda.ym.net.NetRequest;
import com.pda.ym.utils.Constants;
import com.pda.uce.commom.util.LogUtil;

import java.util.List;

/**
 * 定时任务
 *
 * @author xionggaosheng
 */
public class AlarmReceiver extends BroadcastReceiver {

    OffLineUnbindTableDao dao = new OffLineUnbindTableDao();

    @Override
    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();

        if (action == "intent_alarm_log") {
            OffLineUnbindTable firstBean = dao.getFirst();
            if (firstBean != null && firstBean.getForkliftNo() != null) {
                List<OffLineUnbindTable> offLineUnbindTables = dao.queryListByForkliftNo(firstBean.getForkliftNo());

                OffLineUnBindRequest bean = new OffLineUnBindRequest();
                bean.setStatOfflineVos(offLineUnbindTables);
                new NetRequest().setMethod(NetRequest.Method.POST_STRING)
                        .setUrl(Constants.URL_OFFLINE_UNBIND_FORKLIFT)
                        .setRequestObject(new OffLineUnBindRequest())
                        .setResponsClazz(SuccessResponse.class)
                        .setConnTimeOut(10 * 1000)
                        .execute(new UICallBack() {
                            @Override
                            public void onError(String msg) {

                            }

                            @Override
                            public void onSuccess(Object obj) {
                                LogUtil.e("提交成功");
                                SuccessResponse response = (SuccessResponse) obj;
                                if (response.isSuccess()) {

                                }

                            }
                        });
            }


        }

    }
}
